/*    */ package xin.petstore.framework.orm.mybatis.paginator.dialect;
/*    */ 
/*    */ import com.eloancn.framework.orm.mybatis.paginator.domain.PageBounds;
/*    */ import org.apache.ibatis.mapping.MappedStatement;
/*    */ 
/*    */ public class DB2Dialect extends Dialect
/*    */ {
/*    */   public DB2Dialect(MappedStatement mappedStatement, Object parameterObject, PageBounds pageBounds)
/*    */   {
/* 13 */     super(mappedStatement, parameterObject, pageBounds);
/*    */   }
/*    */ 
/*    */   private static String getRowNumber(String sql) {
/* 17 */     StringBuffer rownumber = new StringBuffer(50)
/* 18 */       .append("rownumber() over(");
/*    */ 
/* 20 */     int orderByIndex = sql.toLowerCase().indexOf("order by");
/*    */ 
/* 22 */     if ((orderByIndex > 0) && (!hasDistinct(sql))) {
/* 23 */       rownumber.append(sql.substring(orderByIndex));
/*    */     }
/*    */ 
/* 26 */     rownumber.append(") as rownumber_,");
/*    */ 
/* 28 */     return rownumber.toString();
/*    */   }
/*    */ 
/*    */   private static boolean hasDistinct(String sql) {
/* 32 */     return sql.toLowerCase().indexOf("select distinct") >= 0;
/*    */   }
/*    */ 
/*    */   protected String getLimitString(String sql, String offsetName, int offset, String limitName, int limit) {
/* 36 */     int startOfSelect = sql.toLowerCase().indexOf("select");
/*    */ 
/* 38 */     StringBuffer pagingSelect = new StringBuffer(sql.length() + 100)
/* 39 */       .append(sql.substring(0, startOfSelect))
/* 40 */       .append("select * from ( select ")
/* 41 */       .append(getRowNumber(sql));
/*    */ 
/* 43 */     if (hasDistinct(sql)) {
/* 44 */       pagingSelect.append(" row_.* from ( ")
/* 45 */         .append(sql.substring(startOfSelect))
/* 46 */         .append(" ) as row_");
/*    */     }
/*    */     else {
/* 49 */       pagingSelect.append(sql.substring(startOfSelect + 6));
/*    */     }
/*    */ 
/* 52 */     pagingSelect.append(" ) as temp_ where rownumber_ ");
/*    */ 
/* 55 */     if (offset > 0) {
/* 56 */       pagingSelect.append("between ?+1 and ?");
/* 57 */       setPageParameter(offsetName, Integer.valueOf(offset), Integer.class);
/* 58 */       setPageParameter("__offsetEnd", Integer.valueOf(offset + limit), Integer.class);
/*    */     }
/*    */     else {
/* 61 */       pagingSelect.append("<= ?");
/* 62 */       setPageParameter(limitName, Integer.valueOf(limit), Integer.class);
/*    */     }
/*    */ 
/* 65 */     return pagingSelect.toString();
/*    */   }
/*    */ }

/* Location:           C:\java代码反编译器\core-1.1.4.jar
 * Qualified Name:     com.eloancn.framework.orm.mybatis.paginator.dialect.DB2Dialect
 * JD-Core Version:    0.6.0
 */